package com.hzcrash.beauty;

import java.util.List;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

public class CommentAdapter extends BaseAdapter
{

	private Context context;
	private int resourceId;
	private List<MenuContextObj> group;
	private ViewHolder viewholder;
	private LayoutInflater layoutInflater;

	/**
	 * 
	 * @param context
	 * @param resourceId
	 * @param group
	 */
	public CommentAdapter(Context context, int resourceId, List<MenuContextObj> group)
	{
		this.context = context;
		this.resourceId = resourceId;
		this.group = group;
	}

	public void setGroups(List<MenuContextObj> group)
	{
		this.group = group;
	}

	public int getCount()
	{
		return this.group.size();
	}

	@Override
	public Object getItem(int position)
	{
		return this.group.get(position);
	}

	@Override
	public long getItemId(int position)
	{
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent)
	{
		try
		{
			if (convertView == null)
			{
				this.layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
				convertView = this.layoutInflater.inflate(this.resourceId, null, false);
				viewholder = new ViewHolder();
				viewholder.name = (TextView) convertView.findViewById(R.id.name);
				viewholder.time = (TextView) convertView.findViewById(R.id.time);
				viewholder.comm = (TextView) convertView.findViewById(R.id.comment);
				convertView.setTag(viewholder);
			}
			else
			{
				viewholder = (ViewHolder) convertView.getTag();
			}
			LinearLayout layout = (LinearLayout) convertView.findViewById(R.id.layout_id);
			if (position % 2 == 0)
			{
				layout.setBackgroundColor(Color.rgb(236, 237, 238));
			}
			else
			{
				layout.setBackgroundColor(Color.rgb(224, 226, 227));
			}
			viewholder.name.setText("" + group.get(position).name);
			viewholder.time.setText(group.get(position).date);
			viewholder.time.setVisibility(View.VISIBLE);
			viewholder.comm.setText("" + group.get(position).title);
		} catch (Exception e)
		{
			e.printStackTrace();
		}

		return convertView;
	}

	public class ViewHolder
	{
		private TextView name, time, comm;
	}
}
